<?php
/**
 * View  LaFabbrica.org
 * 
 * @author     luigi.pastore (gigi@la-fabbrica.org)
 * @created    17-mag-2011
 * @package    LaFabbrica
 * @copyright  Copyright (c) 2011 Luigi Pastore
 */
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=true"></script>
<div class="info">
    <h2>Dettagli Location</h2>
    <div>...</div>
</div>
<div id="content">
<div class="col2">
    <div id="detailTableLeft">
	<table cellspacing="0" class="table">
	    <caption><strong>Informazioni Locale</strong><a class="edit" href="/admin/location/edit/id/<?php echo $this->data['location_id'] ?>" title="Modifica">&nbsp;</a></caption>
	    <tbody>
		<tr>
		    <th>Nome:</th>
		    <td><?php echo $this->data['location_name']?></td>
		</tr>
		<tr>
		    <th>Indirizzo:</th>
		    <td>			
		    <?php 
		    $address = NULL;

		    if( $this->data['location_street'] != '' )
			$address .= $this->data['location_street'] .', ';

		    if( $this->data['location_street_number'] != '' )
			$address .= 'N&deg; '. $this->data['location_street_number'] .'<br /> ';

		    if( $this->data['location_loc'] != '' )
			$address .= 'Localit&aacute; '. $this->data['location_loc'] .'<br />';

		    if( $this->data['location_cap'] != '' )
			$address .= $this->data['location_cap'];

		    if( $this->data['location_city'] != '' )
			$address .= ' <strong>'. strtoupper( $this->data['location_city'] ) .'</strong> ';

		    if( $this->data['location_province_id'] != '' )
			$address .= '('. strtoupper( $this->province[$this->data['location_province_id']]['province_long_name'] ) .')';
		    
		    if( $address !== NULL )
		    {
			echo $address;
		    }
		    ?>
		    </td>
		</tr>
		<tr>
		    <th>Info Locale:</th>
		    <td><?php echo $this->data['location_desc']?></td>
		</tr>		
	    </tbody>
	</table>
	<table cellspacing="0" class="table">
	    <caption><strong>Contatti</strong></caption>
	    <tfoot>
		<tr>
		    <td colspan="2">
			<a class="button" href="/admin/location/contatti/id/<?php echo $this->data['location_id'] ?>">Modifica Contatti</a>
		    </td>
		</tr>
	    </tfoot>
	    <tbody>
		<?php
		if( is_array( $this->data['location_contacts'] ) ):
		    foreach( $this->data['location_contacts'] AS $contact ): ?>
		<tr>
		    <th class="section">Nome:</th>
		    <td class="section"><strong><a href="/admin/contatti/vedi/id/<?php echo $contact['contact_id']?>"><?php echo $contact['contact_firstname']?> <?php echo $contact['contact_lastname']?></a></strong></td>
		</tr>
		<tr>
		    <th>Ruolo:</th>
		    <td><?php echo $this->contact_roles[$contact['fab_contacts_role']]?></td>
		</tr>
		<tr>
		    <th>Email Principale:</th>
		    <td><?php echo $contact['contact_email']?></td>
		</tr>
		<tr>
		    <th>Tel Principale:</th>
		    <td><?php echo $contact['contact_phone']?></td>
		</tr>		
		    <?php endforeach;
		endif; ?>
	    </tbody>
	</table>	
    </div>

   <div id="detailTableRight">
	<table cellspacing="0" class="table">
	    <caption><strong>Mappa</strong></caption>
	    <tfoot>
		<tr>
		    <td>
			<a class="button" href="/admin/contatti/associa/id/<?php echo $this->data['contact_id']?>">Modifica</a>
		    </td>
		</tr>
	    </tfoot>
	    <tbody>

		<tr>
		    <?php if( $address !== NULL ) : ?>
		    <td id="map-container">
			<div id="map-frame">
			    <!-- Mappa -->
			</div>
		    </td>
		    <?php else: ?>
		    <td><i>Non ci sono abbastanza informazioni sull'indirizzo...</i></td>
		    <?php endif; ?>
		</tr>

	    </tbody>
	</table>
    </div> 
</div>
    </div>
<br style="clear: both;" />
</div>
<script type="text/javascript">
    //<![CDATA[
    
    $("#map-frame").ready(function()
    {
	geocoder = new google.maps.Geocoder();
	/* Info Locale */
	var address	= "<?php echo $this->data['location_name'] .','. $this->data['location_street'] .','.$this->data['location_street_number'] .','. $this->data['location_city'] .' ('.$this->province[$this->data['location_province_id']]['province_long_name'] .')' ?>";
	var title	= "<?php echo $this->data['location_name']?>";

	var myOptions = {
	    zoom: 16,
	    mapTypeId: google.maps.MapTypeId.ROADMAP
	};

	/* Istanzia la mappa */
	var map = new google.maps.Map(document.getElementById("map-frame"),myOptions);

	geocoder.geocode( { 'address': address}, function(results, status) {
	    if (status == google.maps.GeocoderStatus.OK) {
		map.setCenter(results[0].geometry.location);
		var marker = new google.maps.Marker({
		    map: map,
		    position: results[0].geometry.location,
		    animation: google.maps.Animation.DROP,
		    title: title
		});
	    } else {
		alert("Geocode fallito: " + status);
	    }
	});
    });

    //]]>
</script>
